﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_func_word_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();

        ShowData();

        if (!IsPostBack)
        {
            this.Panel2.Visible = false;

            var data = from p in db.ct_profiles
                       select p.country;


            this.DropDownList1.DataSource = data.Distinct();
            this.DropDownList2.DataSource = data.Distinct();
            this.DropDownList1.DataBind();
            this.DropDownList2.DataBind();
        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();

        this.Panel2.Visible = true;
        this.Button1.Visible = false;
    }

    private void ShowData()
    {
        ctpDataContext db = new ctpDataContext();
        String[] ss = {"DCADCA","CDACDA","Cdacad","","465rf"};
      

        var list = from p in db.ct_profiles
                   select new
                   {
                       country = p.country,
                       district = p.continent
                   };
        
        this.GridView1.DataSource = list.Distinct();
        this.GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();

        this.Panel2.Visible = false;
        this.Button1.Visible = true;

        wordlist word = new wordlist();
        word.originalword = this.DropDownList1.SelectedValue.Trim();
        word.sameword = this.DropDownList2.SelectedValue.Trim();
        db.wordlists.InsertOnSubmit(word);

        foreach (ct_profile c in db.ct_profiles)
        {
            if (c.country == this.DropDownList2.SelectedValue)
            {
                c.country = this.DropDownList1.SelectedValue.Trim();
            }
        }
        db.SubmitChanges();

        ShowData();
    }

    private string district(int cont)
    {
        switch (cont) 
        {
            case 1:
                return "美洲";
            case 2:
                return "亞洲";
            default:
                return "尚未設定";
        }
    
    }
}
